{% extends 'admin/base.html' %}

{% block content %}
<div class="tpl-content-wrapper">
    <div class="tpl-content-page-title">注册用户管理</div><br>
    <div class="tpl-portlet-components">
        <div class="portlet-title">
            <div class="caption font-green bold">用户列表</div>
        </div>
        <div class="tpl-block">
            <div class="am-g">
                <div class="am-u-sm-12 am-u-md-6">
                    <div class="am-btn-toolbar">
                        <div class="am-btn-group am-btn-group-xs">
                            <button type="button" class="am-btn am-btn-default am-btn-success"><span class="am-icon-plus"></span> 新增</button>
                            <button type="button" class="am-btn am-btn-default am-btn-danger"><span class="am-icon-trash-o"></span> 删除</button>
                        </div>
                    </div>
                </div>
                <div class="am-u-sm-12 am-u-md-3">
                    <div class="am-input-group am-input-group-sm">
                        <input type="text" class="am-form-field">
                        <span class="am-input-group-btn">
                            <button class="am-btn  am-btn-default am-btn-success tpl-am-btn-success am-icon-search" type="button"></button>
                        </span>
                    </div>
                </div>
            </div>
            <div class="am-g">
                <div class="am-u-sm-12">
                        <table class="am-table am-table-striped am-table-hover table-main">
                            <thead>
                                <tr>
                                    <th class="table-check"><input type="checkbox" class="tpl-table-fz-check"></th>
                                    <th class="table-id">ID</th>
                                    <th class="table-title">用户名</th>
                                    <th class="table-type">邮箱</th>
                                    <th class="table-author am-hide-sm-only">订阅数量</th>
                                    <th class="table-date am-hide-sm-only">最近登录</th>
                                    <th class="table-set">操作</th>
                                </tr>
                            </thead>
                            <tbody>
                            {% for user in users %}
                                <tr>
                                    <td><input type="checkbox"></td>
                                    <td>{{ loop.index }}</td>
                                    <td>{{ user.username }}</td>
                                    <td>{{ user.email }}</td>
                                    <td class="am-hide-sm-only">{{ user.sub|length }}</td>
                                    <td class="am-hide-sm-only">{{ user.timestamp }}</td>
                                    <td>
                                        <div class="am-btn-toolbar">
                                            <div class="am-btn-group am-btn-group-xs">
                                                <button class="am-btn am-btn-default am-btn-xs am-text-secondary js-modal-open" id="edit_btn" data-href="{{ url_for('admin.profile', user_id=user.id) }}"><span class="am-icon-pencil-square-o"></span> 编辑</button>
                                                <form method="post" action="{{ url_for('admin.delete_user', user_id=user.id, next=request.full_path) }}" style="display: inline">
                                                    <input type="hidden" name="csrf_token" value="{{ csrf_token() }}"/>
                                                    <button class="am-btn am-btn-default am-btn-xs am-text-danger am-hide-sm-only" onclick="return confirm('确定删除该用户吗？')"><span class="am-icon-trash-o"></span> 删除</button>
                                                </form>
                                            </div>
                                        </div>
                                    </td>
                                </tr>
                            {% endfor %}
                            </tbody>
                        </table>
                <div id="pop_container"></div>
                        <hr>
                </div>
            </div>
        </div>
    </div>
</div>
{% endblock %}

{% block js %}
<script>
$(function(){
  $("#edit_btn").click(function(){
    var url = $(this).data("href");
    $("#pop_container").load(url, function () {
        $("#edit_popup").modal()
    });
  });
});
</script>
{% endblock %}